
class Solution {
    public int timeRequiredToBuy(int[] tickets, int k) {
        int n = tickets.length;
        int ret = 0;
        for (int i = 0; i < n; i++) {
            if (i <= k) {
                ret += Math.min(tickets[i], tickets[k]);
            } else {
                ret += Math.min(tickets[k] - 1, tickets[i]);
            }
        }
        return ret;
    }
}